利用Delphi里面的IdIcmpClient控制来检测网络是否正常连通

您所在的位置:网站首页 delphi ttask 利用Delphi里面的IdIcmpClient控制来检测网络是否正常连通

利用Delphi里面的IdIcmpClient控制来检测网络是否正常连通

2023-09-03 16:19| 来源: 网络整理| 查看: 265

1、引用以下几个单元

     IdBaseComponent, IdComponent, IdRawBase,  IdRawClient, IdIcmpClient;

2、函数模块

-------------------------------------------------------------------------------------

        功能: 检查网络是否正常连通   

        参数: 无

        返回值: 成功: True   失败: False

       2014年3月22日  编写

-------------------------------------------------------------------------------------

function CheckOnLine: Boolean; const Url = 'www.sina.com'; //广东电信测速 0.08s var aIdICMPClient: TIdICMPClient; begin Result := False; aIdICMPClient := TIdIcmpClient.Create(nil); try aIdICMPClient.ReceiveTimeout := 1000; //1500ms is timeout aIdICMPClient.Host := Url; try aIdICMPClient.Ping(); if (aIdICMPClient.ReplyStatus.FromIpAddress '0.0.0.0') and (aIdICMPClient.ReplyStatus.FromIpAddress '') and (aIdICMPClient.ReplyStatus.BytesReceived > 0) then //有收到数据 Result := True; except Result := False; end; finally aIdICMPClient.Free; end; end;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3